Translation unit (programming)

In C programming language terminology, a translation unit is the ultimate input to a C compiler from which an object file gets generated.[1]

Context

A C program consists of units called source files (or preprocessing files). When the C preprocessor expands a source file with all header files declared by #include directives, the result is a preprocessing translation unit. Further preprocessing translates the preprocessing translation unit into a translation unit. From a translation unit, the compiler generates an object file, which can be further processed and linked (possibly with other object files) to form an executable program.

The bulk of a project's code is typically held in files with a .c suffix (or .c++ or .cpp for C++). Files intended to be included typically have a .h suffix, and generally do not contain function or variable declarations to avoid name conflicts when headers are included in multiple source files, as is often the case. Header files can and often are included in other header files. It is standard practice for all .c files in a project to include at least one .h file.

References

  1. ^ ISO/IEC 9899:TC3 - Committee Draft of the C99 Standard - Section 5.1.1.1